# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  # Usage: page.update
  def update(type,obj)
    page.replace "#{obj.id}", :partial=>"#{type.to_s}_item",:locals=>{type=>obj}
    page[obj.id.to_s].visual_effect :highlight
    page.replace_html("edit_place_#{obj.id}", '')
  end

  def del(obj)
      page.remove("#{obj.id}")
  end


  def get_users_by_level(event,start_index,end_index)
    level_groups=[]
    Level::OPTIONS.each do |level|
      if ((Level::OPTIONS.index(level)<=start_index) && (Level::OPTIONS.index(level)>=end_index)) || (Level::OPTIONS.index(level)>=start_index) && (Level::OPTIONS.index(level)<=end_index)
        level_groups << level
      end
    end
    users = []
    level_groups.each do |level_group|
      users = users +  event.users.find(:all,:conditions=>"level='#{level_group}'")
    end
    users
  end

private

  def error_messages(obj)
    obj.errors.each do |error|
      @error_messages="#{@error_messages}<p>#{error[1]}</p>"
    end
    @error_messages
  end
end
